package com.example.androidlearning.sy7;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.androidlearning.R;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.List;
import java.util.Map;

public class Sy7Activity020 extends AppCompatActivity {

    TextView title;
    TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sy07020);

        title = findViewById(R.id.title);
        text = findViewById(R.id.text);

        Intent intent = getIntent();
        Bundle bundle;
        //判断传过来的bundle，初始化text和title
        if(intent.getBundleExtra("数组") != null){
            bundle = intent.getBundleExtra("数组");
            title.setText("数组");
            String[] arr = bundle.getStringArray("StringArray");
            String tmp = "";
            for(String s : arr){
                tmp += s + "\n" ;
            }
            text.setText(tmp);
        }else if(intent.getBundleExtra("集合") != null){
            title.setText("集合");
            bundle = intent.getBundleExtra("集合");
            List list = bundle.getParcelableArrayList("list");
            String tmp = "";
            for(Map.Entry<String, Object> entry : ((Map<String, Object>)list.get(0)).entrySet()){
                tmp += "key:" + entry.getKey() + "value:" + entry.getValue() + "\n";
            }
            text.setText(tmp);
        }else if(intent.getBundleExtra("对象") != null){
            title.setText("JSON");
            bundle = intent.getBundleExtra("对象");
            Book book = JSON.parseObject(bundle.getString("book"), Book.class);
            text.setText(book.toString());
        }else if(intent.getBundleExtra("Bitmap") != null){
            title.setText("Bitmap");
            ImageView imageView = findViewById(R.id.sy0702_image);
            bundle = intent.getBundleExtra("Bitmap");
            System.out.println(bundle.getParcelable("bitmap"));
            imageView.setImageBitmap((Bitmap) bundle.getParcelable("bitmap"));
        }

    }
}
